<template>
    <view class="tabbar">
        <image class="bj" src="~@/static/tabbar/tabbar_bj.png" mode=""></image> 
        <view class="navigator">
            <view class="navigator-item" v-for="(item,index) in tabBar.list" :key="item.pagePath"
                @click="switchTab(index,item)">
                    <img :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
                    <img :src="item.selectedIconPath" class="icon" v-else>
                    <text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
            </view>
        </view>
    </view>

</template>
<script>
	export default {
		watch: {
			$route: {
				immediate: true,
				handler(to) {
					if (to.meta.isTabBar) {
						// this.__path__ = this.$route.path
						this.showselected = true
						const index = this.tabBar.list.findIndex(item => to.meta.pagePath === item.pagePath)
						if (index > -1) {
							this.selectedIndex = index
						}
					}
				}
			}
		},
		data() {
			return {
				selectedIndex: 0,
				showselected: false,
				tabBar: {
					list: [{
							"pagePath": "pages/index/index",
							"iconPath": require("@/static/tabbar/icon1_hover.png"),
							"selectedIconPath": require("@/static/tabbar/icon1_hover.png"),
							"text": "勤务"
						}
                        , {
							"pagePath": "pages/programme/programme",
							"iconPath": require("@/static/tabbar/icon2.png"),
							"selectedIconPath": require("@/static/logo.png"),
							"text": "日程"
						}
                        , {
							"pagePath": "pages/clock/clock",
							"iconPath": require("@/static/tabbar/icon_center.png"),
							"selectedIconPath": require("@/static/tabbar/icon_center.png"),
							"text": ""
						}
                        , {
							"pagePath": "pages/news/news",
							"iconPath": require("@/static/tabbar/icon3.png"),
							"selectedIconPath": require("@/static/logo.png"),
							"text": "消息"
						}, {
							"pagePath": "pages/my/my",
							"iconPath": require("@/static/tabbar/icon4.png"),
							"selectedIconPath": require("@/static/logo.png"),
							"text": "我的"
						}
					]
				},
			}
		},
		// beforeCreate() {
		// 	this.__path__ = this.$route.path
		// },
		methods: {
			switchTab(index, item) {
				let url = '/' + item.pagePath
				let pagePath = url
				const detail = {
				  index,
				  pagePath
				}
				console.log(detail)
				if (this.$route.path !== url) {
				  // this.__path__ = this.$route.path
				  uni.switchTab({
				    from: 'tabBar',
				    url,
				    detail
				  })
				} else {
				  // UniServiceJSBridge.emit('onTabItemTap', detail)
				}
				this.selectedIndex = index
				// this.$emit('switchTab', detail)
			}
		},
	}
</script>

<style  lang="scss" scoped>
	.tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 180rpx;
		z-index: 999;
        .bj{
            width: 100%;
            height: 100%;
            position: absolute;
            z-index: 10;
        }
	}
 
	.navigator {
		display: flex;
		justify-content: space-between;
        height: 100rpx;
		margin: 0 auto;
        position: relative;
        z-index: 50;
        padding:20rpx 56rpx;
        top:70rpx;
	}
 
	.navigator-item {
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 50rpx;
		height: 100%;
	}
    .navigator-item:nth-child(3){
        .icon{
            width: 164rpx;
            height: 164rpx;
            margin-top:-70rpx;
        }
    }
 
	.item-text {
		margin-top: 6rpx;
		color: #999999;
		font-size: 22rpx;
	}
 
	.text-active {
		color: #255ADA !important;
	}
 
	.icon {
		width: 42rpx;
		height: 42rpx;
	}
</style>